const getUserInfo = function () {
  return new Promise((resolve, reject) => {
    let userinfo = wx.getStorageSync('userinfo')
    if (userinfo) {
      resolve(userinfo)
    } else {
      wx.getSetting({
        success: (res) => {
          if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
              success: (res) => {
                resolve(res.userInfo)
              }
            })
          } else {
            reject()
          }
        }
      })
    }
  })
}

const contentSecCheck = function (content) {
  return new Promise((resolve, reject) => {
    wx.cloud.callFunction({
      name: 'secCheck',
      data: {
        content: content,
        $url: 'content'
      }
    }).then(res => {
      let data = res.result.data
      let { errCode } = data
      console.log('errCode', data)
      switch (errCode) {
        case 87014:
          wx.showToast({
            icon: 'none',
            title: '内容含有违法违规内容'
          })
          reject()
          break;
        case 0:
          resolve()
          break;
        default:
          break;
      }
    })
  })
}


export default {
  getUserInfo,
  contentSecCheck
}